import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'

import user from './modules/user'
import cart from './modules/cart'
import category from './modules/category'
import { StateType } from '@/types/vuexTypes'

export default createStore<StateType>({
  modules: {
    user,
    cart,
    category,
  },
  // 配置插件
  plugins: [
    // 没有参数时，默认存储在localStorage中，默认将所有模块持久化，具体查看文档
    createPersistedState({
      // 存储时的key值
      key: 'fresh-rabbit-store',
      // 指定需要存储的模块
      paths: ['user', 'cart']
    })
  ],
})